local.js ➔ ... ➔ User.load   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 4
dl 0
loc 10
rs 9.2
nop 2
1
'use strict'
2
var mongoose = require('mongoose')
3
var LocalStrategy = require('passport-local').Strategy
4
var User = mongoose.model('User')
5
6
module.exports = new LocalStrategy({
7
  usernameField: 'email',
8
  passwordField: 'password'
9
},
10
  function (email, password, done) {
11
    const options = {
12
      criteria: { email: email },
13
      select: 'name username email hashed_password salt'
14
    }
15
    User.load(options, function (err, user) {
16
      if (err) return done(err)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
17
      if (!user) {
18
        return done(null, false, { message: 'Unknown user' })
19
      }
20
      if (!user.authenticate(password)) {
21
        return done(null, false, { message: 'Invalid password' })
22
      }
23
      return done(null, user)
24
    })
25
  }
26
)
27